﻿using System;

namespace Program14
{
    //定义枚举
    public enum Gender
    { 
        男,
        女,
        其他
    }

    public enum QQState
    { 
        //枚举的成员可以定义它们的整型值
        online=1,
        offine=0,
        leave=2,
        busy=3,
        Qme=4
    }

    class Program
    {
        static void Main(string[] args)
        {
            #region 将枚举类型转换成int
            //QQState state = QQState.online;
            //int n = (int)state;
            //Console.WriteLine("QQ在线枚举成员的值：" + n);
            //Console.WriteLine("QQ在线枚举成员的值：" + (int )QQState.leave);
            //Console.WriteLine("QQ在线枚举成员的值：" + (int)QQState.offine);
            //Console.WriteLine("QQ在线枚举成员的值：" + (int)QQState.busy);
            //Console.WriteLine("QQ在线枚举成员的值：" + (int)QQState.Qme);

            #endregion
            #region 将int 转换成枚举类型
            //int n1 = 5;
            //int n2 = 4;
            //var state1 = (QQState)n1;
            //var state2 = (QQState)n2;
            //Console.WriteLine("QQ状态：" + state1);
            //Console.WriteLine("QQ状态：" + state2);
            //Console.WriteLine("QQ在线枚举成员的值：" + (QQState)1);

            #endregion
            #region 将字符串转换为枚举类型
            string s = "其他";
            //将“其他”转换成Gender 其他
            //将字符串类型转换为枚举类型
            Gender g = (Gender)Enum.Parse(typeof(Gender), s);
            Console.WriteLine(g);
            Console.WriteLine((int)g);
            #endregion
            Console.ReadLine();
        }
    }
}
